import gevent
from gevent import monkey
import requests

# 打个补丁，把阻塞操作全部变为非阻塞
monkey.patch_all()

def work1():
    for i in range(100):
        print("这是work1")
        requests.get("http://www.baidu.com")
        gevent.sleep(0.1)   # 使用gevent.sleep模拟 非阻塞

def work2():
    for i in range(100):
        print("这是work2")
        requests.get("http://www.baidu.com")
        gevent.sleep(0.1)

# 创建两个协程任务
g1 = gevent.spawn(work1)
g2 = gevent.spawn(work2)

# 等待所有的协程任务完成
gevent.joinall([g1, g2])